package com.ttwm.controller;

import com.ttwm.pojo.Food;
import com.ttwm.service.FoodService;
import javafx.collections.ObservableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class FoodController {
    @Autowired
    private FoodService foodService;

    @PostMapping(value = {"ttwm/foodAll"})
    public Map<String ,Object> foodAll(){
        Map map = new HashMap<String , Object>();
        List<Food> foodList = foodService.foodAll();
        if (foodList.isEmpty()){
            map.put("success",false);
            map.put("msg","失败");
        }else {
            map.put("success",true);
            map.put("msg","成功");
            map.put("list",foodList);

        }
        return map;
    }

    @PostMapping(value = {"ttwm/foodone"})
    public Map<String ,Object> foodOne(@RequestBody Food food ){
        Map map = new HashMap<String,Object>();
        Food foodId = foodService.foodOne(food.getFoodId());
        if (food != null){
            map.put("success",true);
            map.put("mag","成功");
            map.put("data",foodId);
        }else {
            map.put("success",false);
            map.put("mag","失败");
        }
        return map;
    }

    @PostMapping(value = {"ttwm/likeFood"})
    public Map<String ,Object> likeFood(@RequestBody Food food){
        Map map = new HashMap<String , Object>();
        List<Food> likeFood = foodService.likeFood(food);
        if (likeFood.isEmpty()){
            map.put("success",false);
            map.put("msg","失败");
        }else {
            map.put("success",true);
            map.put("msg","成功");
            map.put("list",likeFood);

        }
        return map;
    }

}
